package com.youngball.web.controller.sys.web.controller;


import com.youngball.business.utill.Code;
import com.youngball.shiro.entity.User;
import com.youngball.shiro.service.ResourceService;
import com.youngball.shiro.service.UserService;
import com.youngball.web.controller.BaseController;
import com.youngball.web.controller.sys.web.bind.annotation.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;


/**

 */
@Controller
public class IndexController extends BaseController {

    @Autowired
    private ResourceService resourceService;
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/menus",method = RequestMethod.GET)
    public ResponseEntity<Map> index(@CurrentUser User loginUser, Model model, @RequestHeader("Accept") String encoding , HttpServletResponse httpServletResponse, HttpEntity<byte[]> requestEntity)
    {
        Map maps=new HashMap();
        String name= loginUser.getUsername();
        Set<String> permissions = userService.findPermissions(name);
       /* List<Resource> menus = resourceService.findMenus(permissions);*/
        maps.put("data",loginUser);
        maps.put("code", Code.SUC.getValue());
        return new ResponseEntity<Map>(maps, responseHeaders, HttpStatus.OK);
    }

    @RequestMapping("/welcome")
    public String welcome() {
        return "welcome";
    }


}
